package gqz.mvvm.view.RecyclerView;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;

import gqz.mvvm.R;
import gqz.mvvm.view.BaseActivity;

/**
 * Created by Administrator on 2018/1/12.
 */

public class RecyclerViewActivity extends BaseActivity {

    private Button btn_lv;
    private RecyclerView rv;

    private ArrayList<String> datas = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler);
        initData();
        initView();
    }

    private void initView() {
        btn_lv = (Button) findViewById(R.id.recycler_btn_listview);
        btn_lv.setOnClickListener(onclick);

        rv = (RecyclerView) findViewById(R.id.recycler_rv);
//        rv.setLayoutManager(new LinearLayoutManager(this));//like listview
        rv.setLayoutManager(new GridLayoutManager(this,5));//like gridview
        rv.setAdapter(new RecyclerAdapter(this, datas));
        rv.addItemDecoration(new ItemDecoration(this,ItemDecoration.VERTICAL_LIST));
    }

    private void initData() {
        for (int i = 'A'; i < 'z'; i++) {
            datas.add("" + (char) i);
        }
    }

    View.OnClickListener onclick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.recycler_btn_listview:
                    break;
            }
        }
    };
}
